﻿namespace Digitalmes.Application.Sys.Roles.Queries;

/// <summary>
/// 分页查询角色命令。
/// </summary>
public record GetRoleListWithPagedQuery : PagedQuery, IRequest<IResult<PagedList<SysRoleDto>>>;

internal sealed class GetRoleListWithPagedQueryHandler(IRepository<SysRole> repo) : IRequestHandler<GetRoleListWithPagedQuery, IResult<PagedList<SysRoleDto>>>
{
    public async Task<IResult<PagedList<SysRoleDto>>> Handle(GetRoleListWithPagedQuery request, CancellationToken cancellationToken)
    {
        var items = await repo.AsQueryable()
            .Includes(m => m.RoleMenus)
            .GetPagedListAsync(request.PageNumber, request.PageSize, cancellationToken);
        return Result.From(items.Adapt<PagedList<SysRoleDto>>());
    }
}
